package com.ruoyi.framework.config.properties;
 
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
 
@Component
@ConfigurationProperties(prefix = "tenant")
public class TenantProperties {
 
    /**
     * 是否开启多租户功能
     */
    private boolean enable = true; // 默认开启，可以在YML中覆盖
 
    /**
     * 多租户 ID 的数据库字段名
     */
    private String column = "tenant_id"; // 默认列名为 tenant_id
 
    /**
     * 需要忽略多租户处理的表名集合 (在配置文件中用逗号分隔)
     */
    private Set<String> ignoreTables = new HashSet<>();

    private static final String SIPLIT_CHAR = ",";
 
    // --- Getters and Setters ---
    public boolean isEnable() {
        return enable;
    }
 
    public void setEnable(boolean enable) {
        this.enable = enable;
    }
 
    public String getColumn() {
        return column;
    }
 
    public void setColumn(String column) {
        this.column = column;
    }
 
    public Set<String> getIgnoreTables() {
        return ignoreTables;
    }
 
    // 这个setter允许YML中用逗号分隔的字符串配置 ignoreTables
    public void setIgnoreTables(String ignoreTablesStr) {
        if (ignoreTablesStr != null && !ignoreTablesStr.isEmpty()) {
      /*      this.ignoreTables = ignoreTablesStr.toLowerCase().split(",")
                    .stream()
                    .map(String::trim)
                    .collect(Collectors.toSet());*/
            this.ignoreTables = Arrays.stream(ignoreTablesStr.toLowerCase().split(SIPLIT_CHAR)).map(String::trim).collect(Collectors.toSet());
        } else {
            this.ignoreTables = new HashSet<>();
        }
    }
}
 